<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_DataGrid_Renderer
 * @subpackage Html
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */


/** @see Zend_DataGrid_Renderer_Html */
require_once 'Zend/DataGrid/Renderer/Html.php';


/**
 * Zend_DataGrid_Renderer_Html_Table
 *
 * @category   Zend
 * @package    Zend_DataGrid_Renderer
 * @subpackage Html
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Table.php 8862 2008-11-09 15:36:00Z azoungrana $
 */
class Zend_DataGrid_Renderer_Html_Table extends Zend_DataGrid_Renderer_Html
{

    /**
     * Initialize the renderer options
     *
     * @return Zend_DataGrid_Renderer_Abstract
     */
    protected function initOptions()
    {
        parent::initOptions();

        $options = array('attributes' => array('border'=>'1', 'cellspacing'=>'0', 'cellpadding'=>'0'),
                         'showPager' => true,
                         'form' => null,
                         'pagerAttributes' => array(),
                         'defaultColumnValues' => array(),
                         'sortingResetsPaging' => true,

                         'pagerAdapterPrefixPath' => array(),
                         'pagerScrollingStylePrefixPath' => array(),
                         'pagerDefaultScrollingStyle' => 'Sliding');

        $this->_options = array_merge($this->_options, $options);

        //AutoScroll, AutoHorizontalScroll, DraggableColumns, ResizableColumns, SortableColumns, HeaderImageUrl

        return $this;
    }


    /**
     * Sets the name for Zend_Form element
     *
     * @param string $value
     */
    public function setForm($value) {}

    /**
     * d
     *
     * @param string $name
     * @param string $value
     */
    public function setPagerAttributes($name, $value) {}

    public function setAutoScroll($value) {}

    public function setAutoHorizontalScroll() {}

    public function setDraggableColumns($value) {}

    public function setResizableColumns($value) {}

    public function setSortableColumns() {}

    /**
     * sets the url of the image to be displayed in header
     */
    public function setHeaderImageUrl($url) {}



    /**
     * Renders the content
     *
     * @param Zend_View_Interface $view
     * @return string
     */
    public function render(Zend_View_Interface $view = null)
    {
        if (null !== $view) {
            $this->setView($view);
        }

        $content = '';
        $content .= '<table ' . $this->_htmlAttribs($this->_options['attributes']) . '>';
        $content .= $this->renderHeader();
        $content .= $this->renderItems();
        $content .= $this->renderFooter();
        $content .= '</table>';

        $content .= $this->renderPager();


        return $content;
    }

    /**
     * Renders the header
     *
     * @return string
     */
    public function renderHeader()
    {
        $options = $this->_options;
        if (!$options['showHeader'])  return '';

        $datagrid = $this->_gridElement;

        $content = '';
        $content .= '<tr ' . $this->_htmlAttribs($options['headerAttributes']) . '>';

        $datagrid->rewind();
        while ($datagrid->valid()) {
            $column = $datagrid->current();
            $content .= $column->getRenderer($this->getType())->renderHeader();
            $datagrid->next();
        }

        $content .= '</tr>';

        return $content;
    }

   /**
     * Renders the items
     *
     * @return string
     */
    public function renderItems()
    {
        $datagrid = $this->_gridElement;
        $items = $datagrid->getItems();
        $options = $this->_options;
        $content = '';
        $i = 0;

        foreach ($items as $item) {
            $i++; $attributes = null; $isAlternatingItem = false;
            if ($i%2) {
                $attributes = $options['itemAttributes'];
            } else if (count($options['alternatingItemAttributes'])) {
                $attributes = $options['alternatingItemAttributes'];
                $isAlternatingItem = true;
            } else {
                $attributes = $options['itemAttributes'];
            }

            $content .= '<tr ' . $this->_htmlAttribs($attributes) . '>';

            $datagrid->rewind();
            while ($datagrid->valid()) {
                $column = $datagrid->current();
                $content .= $column->getRenderer($this->getType())->renderItem($item, $isAlternatingItem);
                $datagrid->next();
            }
            $content .= '</tr>';
        }

        return $content;
    }

   /**
     * Renders the footer
     *
     * @return string
     */
    public function renderFooter()
    {
        $options = $this->_options;
        if (!$options['showFooter']) return '';

        $datagrid = $this->_gridElement;

        $content = '';
        $content .= '<tr ' . $this->_htmlAttribs($options['footerAttributes']) . '>';

        $datagrid->rewind();
        while ($datagrid->valid()) {
            $column = $datagrid->current();
            $content .= $column->getRenderer($this->getType())->renderFooter();
            $datagrid->next();
        }

        $content .= '</tr>';

        return $content;
    }

    /**
     * Renders the pager
     *
     @return string
     */
    public function renderPager()
    {
        $options = $this->_options;
        if ($options['showPager']) return '';

        return '';
    }


}




